package org.soma.sso.client.user;

import org.soma.sso.core.filter.SomaSsoFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = { "org.soma" })
@ImportResource(value = { "classpath:/config/applicationContext-*.xml" })
public class StarterClientUser {

	@Value("${SSO_SERVER_URL}")
	private String ssoServerUrl;

	@Value("${SSO_SERVER_VERIFY_URL}")
	private String ssoServerVerifyUrl;


	public static void main(String[] args) throws Exception {
		SpringApplication.run(StarterClientUser.class, args);
	}

	@Bean
	public FilterRegistrationBean testFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new SomaSsoFilter());
		registration.addUrlPatterns("/*");
		registration.addInitParameter("SSO_SERVER_URL", ssoServerUrl);
		registration.addInitParameter("SSO_SERVER_VERIFY_URL", ssoServerVerifyUrl);
		registration.setName("somaSsoFilter");
		registration.setOrder(1);
		return registration;
	}

}
